﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ECCSystem.EntityClass;

namespace ECCSystem.DataAccess
{
	class ClsTrackTaskBill : DBObject 
	{
		public DataSet GetTrackTaskBill(int intUserID, int intStatus, DateTime dtStart, DateTime dtEnd, int intFlg)
		{
			SqlParameter[] parameters = new SqlParameter[] { 
															new SqlParameter("@UserID", SqlDbType.Int),
															new SqlParameter("@Start", SqlDbType.DateTime),
															new SqlParameter("@Status", SqlDbType.Int),
															new SqlParameter("@Flg", SqlDbType.Int),
															new SqlParameter("@End", SqlDbType.DateTime)
															};
			parameters[0].Value = intUserID;
			parameters[1].Value = dtStart;
			parameters[2].Value = intStatus;
			parameters[3].Value = intFlg;
			parameters[4].Value = dtEnd;
			return RunProcedure("sp_TrackTaskBill_GetList", parameters, "TrackTaskBill");
		}

		public DataSet GetSysInfor()
		{
			return RunProcedure("sp_SysInfor_GetList", new IDataParameter[] { }, "SysInfor");
		}

		//public DataSet GetTrackTaskBillByID(string strID)
		//{
		//    SqlParameter[] parameters = new SqlParameter[] { 
		//                                                    new SqlParameter("@KeyID", SqlDbType.UniqueIdentifier)
		//                                                    };
		//    Guid guid = new Guid(strID);
		//    parameters[0].Value = guid;
		//    return RunProcedure("sp_TrackTaskBill_GetListByID", parameters, "TrackTaskBill");
		//}

		public void AddMailCheck(int intUserID, DateTime dtStart, DateTime dtEnd, string strKeyID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MialCheck_UserID", SqlDbType.Int),
															 new SqlParameter("@MailCheck_StartTime", SqlDbType.DateTime),
															 new SqlParameter("@MailCheck_EndTime", SqlDbType.DateTime),
															 new SqlParameter("@MialCheck_KeyID", SqlDbType.UniqueIdentifier)
														   };
			parameters[0].Value = intUserID;
			parameters[1].Value = dtStart;
			parameters[2].Value = System.DBNull.Value;
			Guid guid = new Guid(strKeyID);
			parameters[3].Value = guid;
			RunProcedure("sp_MailCheck_Add", parameters, "MailCheck");
		}

		public void UpdateMailCheck(int intUserID, DateTime dtStart, DateTime dtEnd, string strKeyID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MialCheck_UserID", SqlDbType.Int),
															 new SqlParameter("@MailCheck_StartTime", SqlDbType.DateTime),
															 new SqlParameter("@MailCheck_EndTime", SqlDbType.DateTime),
															 new SqlParameter("@MialCheck_KeyID", SqlDbType.UniqueIdentifier) };
			parameters[0].Value = intUserID;
			parameters[1].Value = dtStart;
			parameters[2].Value = dtEnd;
			Guid guid = new Guid(strKeyID);
			parameters[3].Value = guid;
			RunProcedure("sp_MailCheck_Update", parameters, "MailCheck");
		}

		public void AddTrackTaskBill(TrackTaskBillEntity objTrackTaskBillEntity)
		{
		
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TrackTaskBill_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_UserID", SqlDbType.Int),
															 new SqlParameter("@OvertimeBill_KeyID", SqlDbType.VarChar,11),
															 new SqlParameter("@CategoryContent_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_Status", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OperatePerson", SqlDbType.NVarChar, 50),
															 new SqlParameter("@TrackTaskBill_StartDate", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_EndTime", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_SendNumber", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_SendNumberAgain", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OvertimeStatus", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_AppointStatus", SqlDbType.Int),
															 new SqlParameter("@CategoryContent_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@Category_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@TrackTaskTime_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_SVHelp", SqlDbType.Bit)
															};

			Guid guid;
			parameters[0].Value = Guid.NewGuid();
			objTrackTaskBillEntity.TrackTaskBill_KeyID = parameters[0].Value.ToString();
			parameters[1].Value = objTrackTaskBillEntity.TrackTaskBill_UserID;
			if (objTrackTaskBillEntity.OvertimeBill_KeyID != "")
			{
				//guid = new Guid(objTrackTaskBillEntity.OvertimeBill_KeyID);
				parameters[2].Value = objTrackTaskBillEntity.OvertimeBill_KeyID;
			}
			else
			{
				parameters[2].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.CategoryContent_KeyID != "")
			{
				guid = new Guid(objTrackTaskBillEntity.CategoryContent_KeyID);
				parameters[3].Value = guid;
			}
			else
			{
				parameters[3].Value = System.DBNull.Value;
			}

			parameters[4].Value = objTrackTaskBillEntity.TrackTaskBill_Status;
			parameters[5].Value = objTrackTaskBillEntity.TrackTaskBill_OperatePerson;

			if (objTrackTaskBillEntity.TrackTaskBill_StartDate != null)
			{
				parameters[6].Value = objTrackTaskBillEntity.TrackTaskBill_StartDate;
			}
			else
			{
				parameters[6].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.TrackTaskBill_EndTime != null)
			{
				parameters[7].Value = objTrackTaskBillEntity.TrackTaskBill_EndTime;
			}
			else
			{
				parameters[7].Value = System.DBNull.Value;
			}
			parameters[7].Value = System.DBNull.Value;
			parameters[8].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumber;
			parameters[9].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumberAgain;
			parameters[10].Value = objTrackTaskBillEntity.TrackTaskBill_OvertimeStatus;
			parameters[11].Value = objTrackTaskBillEntity.TrackTaskBill_AppointStatus;
			parameters[12].Value = objTrackTaskBillEntity.CategoryContent_Name;
			parameters[13].Value = objTrackTaskBillEntity.Category_Name;
			guid = new Guid(objTrackTaskBillEntity.RackTaskTime_KeyID);
			parameters[14].Value = guid;
			parameters[15].Value = objTrackTaskBillEntity.TrackTaskBill_SVHelp;
			
			this.RunProcedure("sp_TrackTaskBill_Add", parameters, "TrackTaskBill");
		}


		public void DeleteTrackTaskBill(string strID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier) };
			Guid guid = new Guid(strID);
			parameters[0].Value = guid;
			this.RunProcedure("sp_TrackTaskBill_Delete", parameters, "TrackTaskBill");
		}

		public void UpdateTrackTaskBill(TrackTaskBillEntity objTrackTaskBillEntity)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TrackTaskBill_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_UserID", SqlDbType.Int),
															 new SqlParameter("@OvertimeBill_KeyID", SqlDbType.VarChar,11),
															 new SqlParameter("@CategoryContent_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_Status", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OperatePerson", SqlDbType.NVarChar, 50),
															 new SqlParameter("@TrackTaskBill_StartDate", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_EndTime", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_SendNumber", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_SendNumberAgain", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OvertimeStatus", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_AppointStatus", SqlDbType.Int),
															 new SqlParameter("@CategoryContent_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@Category_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@TrackTaskTime_KeyID", SqlDbType.UniqueIdentifier)
															};

			Guid guid = new Guid(objTrackTaskBillEntity.TrackTaskBill_KeyID);
			parameters[0].Value = guid;
			parameters[1].Value = objTrackTaskBillEntity.TrackTaskBill_UserID;
			if (objTrackTaskBillEntity.OvertimeBill_KeyID != "")
			{
				//guid = new Guid(objTrackTaskBillEntity.OvertimeBill_KeyID);
				parameters[2].Value = objTrackTaskBillEntity.OvertimeBill_KeyID; ;
			}
			else
			{
				parameters[2].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.CategoryContent_KeyID != "")
			{
				guid = new Guid(objTrackTaskBillEntity.CategoryContent_KeyID);
				parameters[3].Value = guid;
			}
			else
			{
				parameters[3].Value = System.DBNull.Value;
			}

			parameters[4].Value = objTrackTaskBillEntity.TrackTaskBill_Status;
			parameters[5].Value = objTrackTaskBillEntity.TrackTaskBill_OperatePerson;

			if (objTrackTaskBillEntity.TrackTaskBill_StartDate != null)
			{
				parameters[6].Value = objTrackTaskBillEntity.TrackTaskBill_StartDate;
			}
			else
			{
				parameters[6].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.TrackTaskBill_EndTime != null)
			{
				parameters[7].Value = objTrackTaskBillEntity.TrackTaskBill_EndTime;
			}
			else
			{
				parameters[7].Value = System.DBNull.Value;
			}
			parameters[7].Value = System.DBNull.Value;
			parameters[8].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumber;
			parameters[9].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumberAgain;
			parameters[10].Value = objTrackTaskBillEntity.TrackTaskBill_OvertimeStatus;
			parameters[11].Value = objTrackTaskBillEntity.TrackTaskBill_AppointStatus;
			parameters[12].Value = objTrackTaskBillEntity.CategoryContent_Name;
			parameters[13].Value = objTrackTaskBillEntity.Category_Name;
			guid = new Guid(objTrackTaskBillEntity.RackTaskTime_KeyID);
			parameters[14].Value = guid;
			this.RunProcedure("sp_TrackTaskBill_Update", parameters, "TrackTaskBill");
		}

		public void SubmitTrackTaskBill(TrackTaskBillEntity objTrackTaskBillEntity)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TrackTaskBill_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_UserID", SqlDbType.Int),
															 new SqlParameter("@OvertimeBill_KeyID", SqlDbType.VarChar,11),
															 new SqlParameter("@CategoryContent_KeyID", SqlDbType.UniqueIdentifier),
															 new SqlParameter("@TrackTaskBill_Status", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OperatePerson", SqlDbType.NVarChar, 50),
															 new SqlParameter("@TrackTaskBill_StartDate", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_EndTime", SqlDbType.DateTime),
															 new SqlParameter("@TrackTaskBill_SendNumber", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_SendNumberAgain", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_OvertimeStatus", SqlDbType.Int),
															 new SqlParameter("@TrackTaskBill_AppointStatus", SqlDbType.Int),
															 new SqlParameter("@CategoryContent_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@Category_Name", SqlDbType.NVarChar, 100),
															 new SqlParameter("@TrackTaskTime_KeyID", SqlDbType.UniqueIdentifier)
															};

			Guid guid = new Guid(objTrackTaskBillEntity.TrackTaskBill_KeyID);
			parameters[0].Value = guid;
			parameters[1].Value = objTrackTaskBillEntity.TrackTaskBill_UserID;
			if (objTrackTaskBillEntity.OvertimeBill_KeyID != "")
			{
				//guid = new Guid(objTrackTaskBillEntity.OvertimeBill_KeyID);
				parameters[2].Value = objTrackTaskBillEntity.OvertimeBill_KeyID; ;
			}
			else
			{
				parameters[2].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.CategoryContent_KeyID != "")
			{
				guid = new Guid(objTrackTaskBillEntity.CategoryContent_KeyID);
				parameters[3].Value = guid;
			}
			else
			{
				parameters[3].Value = System.DBNull.Value;
			}

			parameters[4].Value = objTrackTaskBillEntity.TrackTaskBill_Status;
			parameters[5].Value = objTrackTaskBillEntity.TrackTaskBill_OperatePerson;

			if (objTrackTaskBillEntity.TrackTaskBill_StartDate != null)
			{
				parameters[6].Value = objTrackTaskBillEntity.TrackTaskBill_StartDate;
			}
			else
			{
				parameters[6].Value = System.DBNull.Value;
			}

			if (objTrackTaskBillEntity.TrackTaskBill_EndTime != null)
			{
				parameters[7].Value = objTrackTaskBillEntity.TrackTaskBill_EndTime;
			}
			else
			{
				parameters[7].Value = System.DBNull.Value;
			}

			parameters[8].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumber;
			parameters[9].Value = objTrackTaskBillEntity.TrackTaskBill_SendNumberAgain;
			parameters[10].Value = objTrackTaskBillEntity.TrackTaskBill_OvertimeStatus;
			parameters[11].Value = objTrackTaskBillEntity.TrackTaskBill_AppointStatus;
			parameters[12].Value = objTrackTaskBillEntity.CategoryContent_Name;
			parameters[13].Value = objTrackTaskBillEntity.Category_Name;
			guid = new Guid(objTrackTaskBillEntity.RackTaskTime_KeyID);
			parameters[14].Value = guid;
			this.RunProcedure("sp_TrackTaskBill_UpdateBySubmit", parameters, "TrackTaskBill");
		}
	}
}
